home *** CD-ROM | disk | FTP | other *** search
- #
- # profile.test
- #
- # Tests for the profile command and profrep procedure.
- #---------------------------------------------------------------------------
- # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: profile.test,v 2.0 1992/10/16 04:50:07 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- #
- # Function to build a list from the profile output data with each entry
- # contain the call stack and call count. The list is returned sorted by
- # call stack.
- #
-
- proc SumCntData {profDataVar} {
- upvar $profDataVar profData
- set sumData {}
- foreach stack [array names profData] {
- lappend sumData [list $stack [lindex $profData($stack) 0]]
- }
- return [lsort $sumData]
- }
-
- proc ProcA1 {} {ProcB1}
- proc ProcB1 {} {ProcC1;ProcC1}
- proc ProcC1 {} {}
-
- Test profile-1.1 {profile count tests} {
- profile on
- ProcA1
- profile off profData
- SumCntData profData
- } 0 [list {<global> 1} \
- {{ProcA1 <global>} 1} \
- {{ProcB1 ProcA1 <global>} 1} \
- {{ProcC1 ProcB1 ProcA1 <global>} 2}]
-
- proc ProcA2 {} {ProcB2}
- proc ProcB2 {} {ProcC2}
- proc ProcC2 {} {uplevel ProcD2; ProcD2}
- proc ProcD2 {} {}
-
- Test profile-1.2 {profile count tests} {
- profile on
- ProcA2
- profile off profData
- SumCntData profData
- } 0 [list {<global> 1} \
- {{ProcA2 <global>} 1} \
- {{ProcB2 ProcA2 <global>} 1} \
- {{ProcC2 ProcB2 ProcA2 <global>} 1} \
- {{ProcD2 ProcB2 ProcA2 <global>} 1} \
- {{ProcD2 ProcC2 ProcB2 ProcA2 <global>} 1}]
-
- proc ProcA3 {} {ProcB3}
- proc ProcB3 {} {catch {ProcC3};ProcE3}
- proc ProcC3 {} {ProcD3}
- proc ProcD3 {} {error baz}
- proc ProcE3 {} {}
-
- Test profile-1.3 {profile count tests} {
- profile on
- ProcA3
- profile off profData
- SumCntData profData
- } 0 [list {<global> 1} \
- {{ProcA3 <global>} 1} \
- {{ProcB3 ProcA3 <global>} 1} \
- {{ProcC3 ProcB3 ProcA3 <global>} 1} \
- {{ProcD3 ProcC3 ProcB3 ProcA3 <global>} 1} \
- {{ProcE3 ProcB3 ProcA3 <global>} 1}]
-
- #
- # Function to build a list from the profile output data with each entry
- # contain the call stack and call count. The list is returned sorted by
- # CPU time. CPU time is not included in the return, since it can't be
- # verified exactly, only approximately.
- #
-
- proc SumCpuData {profDataVar} {
- upvar $profDataVar profData
- set sumData {}
- foreach stack [array names profData] {
- lappend sumData [list [format %032d [lindex $profData($stack) 2]] \
- $stack [lindex $profData($stack) 0]]
- }
- set retData {}
- foreach entry $sumData {
- lappend retData [lrange $entry 1 end]
- }
- return [lsort $retData]
- }
-
- proc EatTime {amount} {
- set end [expr [lindex [times] 0]+$amount]
- while {[lindex [times] 0] < $end} {
- format %d 100 ;# kind of slow command.
- }
- }
-
- proc ProcA4 {} {ProcB4;ProcC4;ProcD4}
- proc ProcB4 {} {EatTime 1}
- proc ProcC4 {} {EatTime 100}
- proc ProcD4 {} {EatTime 1000}
-
- Test profile-2.1 {profile CPU time tests} {
- profile on
- ProcA4
- profile off profData
- SumCpuData profData
- } 0 [list {<global> 1} \
- {{EatTime ProcB4 ProcA4 <global>} 1} \
- {{EatTime ProcC4 ProcA4 <global>} 1} \
- {{EatTime ProcD4 ProcA4 <global>} 1} \
- {{ProcA4 <global>} 1} {{ProcB4 ProcA4 <global>} 1} \
- {{ProcC4 ProcA4 <global>} 1} {{ProcD4 ProcA4 <global>} 1}]
-
- proc ProcA1 {} {ProcB1;set a 1;incr a}
- proc ProcB1 {} {ProcC1;ProcC1}
- proc ProcC1 {} {set a 1;incr a}
-
- Test profile-3.1 {profile -command tests} {
- profile -commands on
- ProcA1
- profile off profData
- SumCntData profData
- } 0 [list {<global> 1} \
- {{ProcA1 <global>} 1} \
- {{ProcB1 ProcA1 <global>} 1} \
- {{ProcC1 ProcB1 ProcA1 <global>} 2} \
- {{incr ProcA1 <global>} 1} \
- {{incr ProcC1 ProcB1 ProcA1 <global>} 2} \
- {{profile <global>} 1} {{set ProcA1 <global>} 1} \
- {{set ProcC1 ProcB1 ProcA1 <global>} 2}]
-
- Test profile-4.1 {profile error tests} {
- profile off
- } 1 {wrong # args: profile [-commands] on|off arrayVar}
-
- Test profile-4.2 {profile error tests} {
- profile baz
- } 1 {expected one of "on" or "off", got "baz"}
-
- Test profile-4.3 {profile error tests} {
- profile -comman on
- } 1 {expected option of "-commands", got "-comman"}
-
- Test profile-4.4 {profile error tests} {
- profile -commands off
- } 1 {wrong # args: profile [-commands] on|off arrayVar}
-
- Test profile-4.5 {profile error tests} {
- profile -commands
- } 1 {wrong # args: profile [-commands] on|off arrayVar}
-
- Test profile-4.6 {profile error tests} {
- profile -commands on foo
- } 1 {wrong # args: profile [-commands] on|off arrayVar}
-
- Test profile-4.7 {profile error tests} {
- profile off foo
- } 1 {profiling is not currently enabled}
-
- Test profile-4.8 {profile error tests} {
- profile on
- profile on
- } 1 {profiling is already enabled}
- profile off foo
-
- #
- # Set up some dummy profile data for the report tests. The data is not
- # realistic, but designed so that no two numbers that are sorted on are the
- # same.
- #
- catch {unset profData}
- set baz {EatTime ProcB4 ProcA4}
- set profData($baz) {4 800 10}
- set baz {ProcC4 ProcA4}
- set profData($baz) {3 1000 100}
- set baz {EatTime ProcC4 ProcA4}
- set profData($baz) {2 1000 100}
- set baz {ProcD4 ProcA4}
- set profData($baz) {1 100 1070}
- set baz ProcA4
- set profData($baz) {5 1250 1180}
- set baz {EatTime ProcD4 ProcA4}
- set profData($baz) {6 1070 1070}
- set baz {ProcB4 ProcA4}
- set profData($baz) {7 80 11}
-
- #
- # Read the profile report into memory and purge the file
- #
- proc GetProfRep {fileName} {
- set fh [open $fileName]
- set data [read $fh]
- close $fh
- unlink $fileName
- return $data
- }
-
- rename SAVED_UNKNOWN unknown
-
- Test profile-5.1 {profrep tests} {
- profrep profData "calls" 1 prof.tmp "Profile Test 5.1"
- GetProfRep prof.tmp
- } 0 {-----------------------------------------------------
- Profile Test 5.1
- -----------------------------------------------------
- Procedure Call Stack Calls Real Time CPU Time
- -----------------------------------------------------
- ProcB4 7 80 11
- ProcA4 5 1250 1180
- EatTime 4 800 10
- ProcC4 3 1000 100
- ProcD4 1 100 1070
- }
-
- Test profile-5.2 {profrep tests} {
- profrep profData "real" 1 prof.tmp "Profile Test 5.2"
- GetProfRep prof.tmp
- } 0 {-----------------------------------------------------
- Profile Test 5.2
- -----------------------------------------------------
- Procedure Call Stack Calls Real Time CPU Time
- -----------------------------------------------------
- ProcA4 5 1250 1180
- ProcC4 3 1000 100
- EatTime 4 800 10
- ProcD4 1 100 1070
- ProcB4 7 80 11
- }
-
- Test profile-5.3 {profrep tests} {
- profrep profData "cpu" 1 prof.tmp "Profile Test 5.3"
- GetProfRep prof.tmp
- } 0 {-----------------------------------------------------
- Profile Test 5.3
- -----------------------------------------------------
- Procedure Call Stack Calls Real Time CPU Time
- -----------------------------------------------------
- ProcA4 5 1250 1180
- ProcD4 1 100 1070
- ProcC4 3 1000 100
- ProcB4 7 80 11
- EatTime 4 800 10
- }
-
- Test profile-5.4 {profrep tests} {
- profrep profData "cpu" 2 prof.tmp "Profile Test 5.4"
- GetProfRep prof.tmp
- } 0 {-----------------------------------------------------
- Profile Test 5.4
- -----------------------------------------------------
- Procedure Call Stack Calls Real Time CPU Time
- -----------------------------------------------------
- ProcA4 5 1250 1180
- ProcD4 ProcA4 1 100 1070
- EatTime ProcD4 6 1070 1070
- ProcC4 ProcA4 3 1000 100
- EatTime ProcC4 2 1000 100
- ProcB4 ProcA4 7 80 11
- EatTime ProcB4 4 800 10
- }
-
- Test profile-5.5 {profrep tests} {
- profrep profData "cpu" 10 prof.tmp "Profile Test 5.5"
- GetProfRep prof.tmp
- } 0 {------------------------------------------------------
- Profile Test 5.5
- ------------------------------------------------------
- Procedure Call Stack Calls Real Time CPU Time
- ------------------------------------------------------
- ProcA4 5 1250 1180
- ProcD4 ProcA4 1 100 1070
- EatTime ProcD4 ProcA4 6 1070 1070
- ProcC4 ProcA4 3 1000 100
- EatTime ProcC4 ProcA4 2 1000 100
- ProcB4 ProcA4 7 80 11
- EatTime ProcB4 ProcA4 4 800 10
- }
-
- unset foo
- rename unknown SAVED_UNKNOWN
-
-